package com.yanqu.road.dao.impl.channelcenter.washe;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.washe.config.WasheModeConfig;
import com.yanqu.road.utils.date.DateHelper;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WasheModeConfigDaoImpl extends TempDao {

    private static String getWasheModeConfigSql = "select * from `t_n_washepvp_gamemode` where `activityId`=?";

    public Map<Integer, WasheModeConfig> getWasheModeConfigMap(int activityId) {
        Map<Integer, WasheModeConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getChannelCenterDb());
            call = getDb().getConnection().prepareCall(getWasheModeConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                WasheModeConfig washeModeConfig = new WasheModeConfig();
                washeModeConfig.setActivityId(rs.getInt("activityId"));
                washeModeConfig.setModeId(rs.getInt("modeId"));
                washeModeConfig.setMaxRound(rs.getInt("maxRound"));
                washeModeConfig.setMaxStep(rs.getInt("maxStep"));
                washeModeConfig.setClearTime(rs.getLong("clearTime") * DateHelper.SECOND_MILLIONS);
                washeModeConfig.setExParam(rs.getString("exParam"));
                map.put(washeModeConfig.getModeId(), washeModeConfig);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
